<?php
use oxide\ui\html;
use oxide\validation\EmailValidator;
/*
 * building the base for the support form
 */

class SupportForm extends html\Form
{
	// setting up the base elements in the form
	public function setup($subjects = null)
	{
		// validator container
		$validatorContainer = $this->getInputValidation()->getValidatorContainer();
		
		$this->addControl(
				  new html\InputControl('text', 'fullname', null, 'Full Name:')
				  );
		$this->addControl(
				  new html\InputControl('email', 'email', null, 'Email:')
				  );
		$validatorContainer->setRequired(array('fullname', 'email'));
		
		// validation rules
		$validator_email = new EmailValidator();
		$validator_email->setErrorMessage('Please enter a valid email');
		$validator_length = new \oxide\validation\StringLengthValidator(7, 50);
		$validatorContainer->addValidator($validator_email, 'email');
		$validatorContainer->addValidator($validator_length, 'email');

		// check if subjects are supplied, if true, add the element and validation to the form
		if($subjects) {
			$subjectControl = new html\SelectControl('subject', null, 'Subject:');
			$subjectControl->addItems($subjects);
			$this->addControl($subjectControl);
			$validatorContainer->addRequired('subject');
		}

	}
	
	/**
	 * rendering the form
	 * @param type $sender
	 * @return type 
	 */
	public function render($sender = null)
	{
		$this->addControl(
				  new html\ButtonControl('submit', 'submit', null, "Submit", array("formnovalidate"=>"formnovalidate"))
				  );
		
		return parent::render();
	}

}

?>